package leetcode;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

/**
 * @Project : algorithm-learning-java
 * @Package : leetcode
 * @Author : Ruoyu Wang
 * @User : Momenta
 * @DateTime : 2024/1/10 11:09
 */
public class Q0017 {

    String[] map = {"", "", "abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz"};

    List<String> res = new ArrayList<>();
    StringBuilder sb = new StringBuilder();

    private void dfs(String digits, int k) {
        if (k == digits.length()) {
            res.add(sb.toString());
            return;
        }
        String str = map[digits.charAt(k) - '0'];
        for (int i = 0; i < str.length(); i++) {
            sb.append(str.charAt(i));
            dfs(digits, k + 1);
            sb.deleteCharAt(sb.length() - 1);
        }
    }

    public List<String> letterCombinations(String digits) {
        if (!digits.isEmpty()) {
            dfs(digits, 0);
        }
        return res;
    }
}
